<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SensorData</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css">
    <link rel="shortcut icon" href="">

    <style>
        body {
            align-items: center;
            background-color: var(--white);
            background: url("../../../鹿鸣1.jpg");
            /* 决定背景图像的位置是在视口内固定，或者随着包含它的区块滚动。 */
            /* https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-attachment */
            background-attachment: fixed;
            background-position: center;
            background-repeat: no-repeat;
            background-size: cover;
            display: grid;
            place-items: center;
        }

        .form {
            background-color: var(--white);
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            padding: 0 3rem;
            height: 100%;
            text-align: center;
        }

        table thead th {
            background-color: #53a285;
            color: #c2e7e0;
        }

        th,
        td {
            border: 1px solid #999;
            text-align: center;
            padding: 10px 0;
        }

        table thead tr {
            background-color: #5fbc9b;
            color: #a7a8bd;
        }

        table tbody {
            height: 200px;
            width: 900px;
            overflow: auto;
            text-align: center;
        }

        table tbody tr:nth-child(odd) {
            background-color: #abd19d;
        }

        table tbody tr:nth-child(even) {
            background-color: #7fc5a6;
        }

        table tbody tr:hover {
            background-color: #ccc;
        }

        table tbody tr td:first-child {
            color: #eee;
        }

        table tfoot tr td {
            text-align: right;
            padding-right: 20px;
        }

        .title {
            font-weight: 300;
            margin: 0;
            margin-bottom: 1.25rem;
            background-color: #53a285;
            color: #abd19d;
        }

        .filter {
            width: 500;
        }

        .filter ul li {
            width: 500;
            height: 50px;
            margin-bottom: 5px;
        }

        .filter ul li input {
            height: 30px;
        }
    </style>
</head>

<body style="text-align: center;">
    <br /><br /><br />
    <div class="header">
        <h1 class="title">DataFilter</h1>
    </div>
    <br /><br />
    <form method="get" action="/source/include/database/SensorDataFilter.php" class="form" id="form1">
        <div class="filter">
            <ul>
                <li>
                    GatewayID：&nbsp;&nbsp;
                    <input type="search" name="网关ID" id="网关ID" class="input">
                    </input>
                </li>
                <li>
                    NodeName：&nbsp;
                    <input type="search" name="节点ID" id="节点ID" class="input">
                    </input>
                </li>
                <li>
                    Time：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="datetime-local" name="SmallTime" id="SmallTime">
                    </input>
                    - - - -
                    <input type="datetime-local" name="BigTime" id="BigTime">
                    </input>
                </li>
                <li>
                    <input type="submit" name="query" value="查询数据" class="layui-btn layui-btn-radius" />
                </li>
            </ul>
        </div>
    </form>
    <h1 class="title">-----------------------------------------------------</h1>



</body>

</html>

<?php

require_once dirname(dirname(__FILE__)) . '/config/ConfigLoader.php';

require_once dirname(dirname(dirname(__FILE__))) . '/function/function_core.php';
require_once dirname(__FILE__) . '/DBManager.php';
require_once getTablesFile() . "/table_application_sensorData.php";


global $time;
$time = array();
global $where;
$where = "";

if (!empty($_GET[COLUMN_Gateway])) {
    $where .= COLUMN_Gateway . "='" . $_GET[COLUMN_Gateway] . "'";
}
if (!empty($_GET[COLUMN_NodeName])) {
    if (empty($where)) {
        $where .= COLUMN_NodeName . "='" . $_GET[COLUMN_NodeName] . "'";
    } else {
        $where .= " AND ";
        $where .= COLUMN_NodeName . "='" . $_GET[COLUMN_NodeName] . "'";
    }
}

if (!empty($_GET[SMALLTIME])) {
    $time[SMALLTIME] = $_GET[SMALLTIME];
}
if (!empty($_GET[BIGTIME])) {
    $time[BIGTIME] = $_GET[BIGTIME];
}

if (empty($where)) {
    $data = TableArray("table_application_sensorData")->fetch_all_data();
} else {
    $data = TableArray("table_application_sensorData")->fetch_all_assoc($where);
}
echo "<h2 class='title'>Sensor Data</h2>";
if (!empty($data) && !empty($_GET[SMALLTIME]) && !empty($_GET[BIGTIME])) {
    $newdata = filterForTime(count($data), $time, $data);
    createTable(count($newdata) + 1, $TableSensorDataHeaderArray, $newdata);
} else if (!empty($data)) {
    createTable(count($data) + 1, $TableSensorDataHeaderArray, $data);
} else {
    echo "<h3>This SensorData is NULL</h3>";
}


// echo "<pre>";
// print_r($data);
// echo "<pre>";
